package com.milkshopbackend.milkshop.Service.impl;

import com.milkshopbackend.milkshop.Service.ProductSpecService;
import com.milkshopbackend.milkshop.entity.ProductSpec;
import com.milkshopbackend.milkshop.mapper.ProductSpecMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductSpecServiceImpl implements ProductSpecService {
    @Autowired
    private ProductSpecMapper productSpecMapper;

    @Override
    public void addSpec(ProductSpec spec) {
        productSpecMapper.insert(spec);
    }

    @Override
    public void updateSpec(ProductSpec spec) {
        productSpecMapper.updateById(spec);
    }

    @Override
    public void deleteSpec(Long specId) {
        productSpecMapper.deleteById(specId);
    }

    @Override
    public List<ProductSpec> getSpecsByProductId(Long productId) {
        return productSpecMapper.selectList(
                new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<ProductSpec>().eq("product_id",
                        productId));
    }

    @Override
    public ProductSpec getSpecById(Long specId) {
        return productSpecMapper.selectById(specId);
    }
}